const filterDialog = {
  state: {
    dialogOpend: false,
    filterResult: {}
  },
  mutations: {
    SET_OPEND: (state, opend) => {
      state.dialogOpend = opend
    },
    SET_SUPPLIER: (state, supplier) => {
      state.filterResult.supplier = supplier
    },
    SET_REDEEM: (state, redeem) => {
      state.filterResult.redeem = redeem
    },
    SET_ITEM: (state, {
      key,
      item
    }) => {
      // console.log(key);
      // console.log(item);
      // console.log(state.filterResult);
      // var exist = state.filterResult.some(temp=>{
      //   return temp.key == key;
      // });

      // if (!exist) {
      //   state.filterResult.push({key,item});
      // }
      // else{
      //   state.filterResult.some(temp=>{
      //     if (temp.key == key) {
      //       temp.item = item;
      //       return true;
      //     }
      //   })
      // }

    }
  },
  actions: {
    DialogSwitch: ({
      commit
    }, opend) => {
      commit('SET_OPEND', opend)
    },
    SelectedItem: ({
      commit
    }, {
      filterKey: key,
      currentRow: item
    }) => {
      return new Promise((resolve, reject) => {
        if (item) {
          commit('SET_ITEM', {
            key,
            item
          })
          resolve()
        }
        reject(new Error('something bad happened'))
      })
    }
  }
}

export default filterDialog
